package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DbChat;
import com.ruoyi.system.service.IDbChatService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 聊天列Controller
 * 
 * @author ruoyi
 * @date 2025-03-22
 */
@RestController
@RequestMapping("/system/chat")
public class DbChatController extends BaseController
{
    @Autowired
    private IDbChatService dbChatService;

    /**
     * 查询聊天列列表
     */
    @PreAuthorize("@ss.hasPermi('system:chat:list')")
    @GetMapping("/list")
    public TableDataInfo list(DbChat dbChat)
    {
        startPage();
        List<DbChat> list = dbChatService.selectDbChatList(dbChat);
        return getDataTable(list);
    }

    /**
     * 导出聊天列列表
     */
    @PreAuthorize("@ss.hasPermi('system:chat:export')")
    @Log(title = "聊天列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DbChat dbChat)
    {
        List<DbChat> list = dbChatService.selectDbChatList(dbChat);
        ExcelUtil<DbChat> util = new ExcelUtil<DbChat>(DbChat.class);
        util.exportExcel(response, list, "聊天列数据");
    }

    /**
     * 获取聊天列详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:chat:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dbChatService.selectDbChatById(id));
    }

    /**
     * 新增聊天列
     */
    @PreAuthorize("@ss.hasPermi('system:chat:add')")
    @Log(title = "聊天列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DbChat dbChat)
    {
        return toAjax(dbChatService.insertDbChat(dbChat));
    }

    /**
     * 修改聊天列
     */
    @PreAuthorize("@ss.hasPermi('system:chat:edit')")
    @Log(title = "聊天列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DbChat dbChat)
    {
        return toAjax(dbChatService.updateDbChat(dbChat));
    }

    /**
     * 删除聊天列
     */
    @PreAuthorize("@ss.hasPermi('system:chat:remove')")
    @Log(title = "聊天列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dbChatService.deleteDbChatByIds(ids));
    }
}
